added custom one-site matrix observables for non-qubit local dimensions, including named position observables - #497
Conversation
Signed-off-by: linusschulte <119408387+linusschulte@users.noreply.github.com>
|
@linusschulte Can you do a couple things
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Regarding your first review point: |
Signed-off-by: linusschulte <119408387+linusschulte@users.noreply.github.com>
Signed-off-by: linusschulte <119408387+linusschulte@users.noreply.github.com>
Signed-off-by: linusschulte <119408387+linusschulte@users.noreply.github.com>
|
@coderabbitai review |
✅ Action performedReview finished.
|
📝 WalkthroughSummary by CodeRabbit
WalkthroughThis PR adds custom matrix and position observables for non-qubit local dimensions, extends ChangesCustom Observable Support
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Example
participant Observable
participant AnalogSimParams
participant Simulator
participant Result
Example->>Observable: create position observable
Example->>AnalogSimParams: configure observable sampling
AnalogSimParams->>Simulator: run evolution
Simulator-->>Result: return expectation_values
Result-->>Example: provide position expectation
Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/mqt/yaqs/core/data_structures/mps.py`:
- Around line 1121-1124: In the two-site observable branch identified by
observable.gate.interaction == 2, validate that exactly two sites are provided
and that mat has shape (d_i * d_j, d_i * d_j) before indexing sites or
performing contraction; raise the documented ValueError for invalid input while
preserving the existing valid-input path.
In `@src/mqt/yaqs/core/libraries/gate_library.py`:
- Around line 1698-1705: Update the position validation before the dtype
coercion in the constructor’s initialization block to detect complex-valued
inputs and raise ValueError for them, rather than allowing np.asarray to discard
imaginary components. Preserve the existing non-empty, one-dimensional,
finite-value checks and diagonal matrix initialization for valid real positions.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 72d073df-31a2-4dfd-9d49-fc56589172b2
📒 Files selected for processing (9)
CHANGELOG.mddocs/examples/simulation_parameters.mddocs/examples/trapped_ion.mdsrc/mqt/yaqs/core/data_structures/mps.pysrc/mqt/yaqs/core/data_structures/simulation_parameters.pysrc/mqt/yaqs/core/libraries/gate_library.pytests/core/data_structures/test_mpo.pytests/core/data_structures/test_mps.pytests/core/data_structures/test_simulation_parameters.py
Description
This PR adds support for one-site higher-level/qudit observables using new
LocalOperatorin order to enable measurement of things like physical position.Tests cover Observable construction from local matrices, MPS expectation evaluation on non-qubit sites, dimension-mismatch errors, and the proper expected trapped-ion trajectory.
Note: Local Observables are still called "Gates" due to qubit-only heritage. That might be a bit misleading for non-logical operators but renaming that consistently is outside of this PR's scope.
Checklist
If PR contains AI-assisted content:
PR was assisted by ChatGPT Codex 5.5 via VS Code Codex Plugin
Assisted-by: [Model Name] via [Tool Name]footer.